'''
Created on Mar 25, 2013

@author: LONG HOANG GIANG
'''

from lxml import etree
import cStringIO
import sys

XML_PARSER = etree.XMLParser(encoding='utf-8')
HTML_PARSER = etree.HTMLParser(encoding='utf-8')

def buildTree(html, parser=HTML_PARSER, base_url=None):
    tree = None
    try:
        tree = etree.parse(cStringIO.StringIO(html), parser=parser, base_url=base_url)
    except:
        print sys.exc_info()[1]
    return tree

class HttpResponse():
    
    _data = ""
    _info = ""
    _code = 0
    _url = ""
    _cookie = ""
    
    def __init__(self, data):
        self._data = data
        
    def set(self, info, code, url, cookie):
        self._info = info
        self._code = code
        self._url = url
        self._cookie = cookie
        
    def gethtml(self):
        return self._data
    
    def getcookie(self):
        return self._cookie
    
    def setcookie(self, cookie):
        self._cookie = cookie
    
    def build_tree(self):
        tree = buildTree(self.gethtml())
        return tree
        
